﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LDSP.BRL;
using BYFW.DAL;
using System.Data;

namespace LDSP.UI.EnterpriseAdmin
{
    public partial class PrincipalReport : BRL.BaseEnterpriseAdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.RB())
                {
                    if (!IsPostBack)
                    {
                        this.InitData();
                    }

                    ShowReport();
                }
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }

        protected bool RB()
        {
            return this.AllowEnterpriseUser();
        }

        protected void InitData()
        {
            BindDDLPeriod();
        }

        private void BindDDLPeriod()
        {
            this.ddl_period.Items.Clear();

            for (int i = 2009; i <= DateTime.Now.Year; i++)
            {
                this.ddl_period.Items.Add(i.ToString());
            }

            if (this.ddl_period.Items.Count > 0)
            {
                this.ddl_period.SelectedIndex = this.ddl_period.Items.Count - 1;
            }
        }

        protected void CreateReportInfo(int year)
        {
            ReportInfo ri = new ReportInfo();
            ri.DataSource = new R_EnterpriseCodification().GetReportForPrincipal(this.LoginUser.EnterpriseID);
            ri.XName = "principal";
            ri.YName = "number";
            ri.Title = "法规责任人图表";
            this.Session["principalReport"] = ri;

            this.img_report.ImageUrl = "ReportImg.aspx?" + Guid.NewGuid().ToString();
        }

        protected void btn_ok_Click(object sender, EventArgs e)
        {
            ShowReport();
        }

        private void ShowReport()
        {
            int year = DateTime.Now.Year;

            if (this.ddl_period.SelectedIndex >= 0)
            {
                year = Int32.Parse(this.ddl_period.SelectedValue);
            }

            this.CreateReportInfo(year);
        }
    }
}